package com.banksoft.cps.service.impl;

import com.banksoft.cps.bean.MonitorProduct;
import com.banksoft.cps.bean.query.MonitorProductQuery;
import com.banksoft.cps.dao.MonitorProductDao;
import com.banksoft.cps.service.MonitorProductService;
import com.banksoft.cps.util.UUIDFactory;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by rongzhao.zhu on 2017/12/29.
 */
@Service
public class MonitorProductServiceImpl implements MonitorProductService {
    @Autowired
    MonitorProductDao monitorProductDao;

    @Override
    public List<MonitorProduct> list(MonitorProductQuery query) {
        return monitorProductDao.list(query);
    }

    @Override
    public long count(MonitorProductQuery query) {
        return monitorProductDao.count(query);
    }

    @Override
    public void save(MonitorProduct bean) {
          if(StringUtils.isNotBlank(bean.getId())){
                monitorProductDao.update(bean);
          }else {
              bean.setId(UUIDFactory.random());
              bean.setCreateTime(System.currentTimeMillis());
              monitorProductDao.insert(bean);
          }

    }
    @Override
    public MonitorProduct findById(String id) {
        if(StringUtils.isNotBlank(id)){
            MonitorProductQuery query = new MonitorProductQuery();
            query.setId(id);
            List<MonitorProduct>  list = monitorProductDao.list(query);
            if(!list.isEmpty()){
                return list.get(0);
            }
        }
        return null;
    }

    @Override
    public void delete(String[] ids) {
        monitorProductDao.delete(ids);
    }
}
